// miniprogram/pages/首页/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    swiperHeight: 200,
    lxElist:[
      {
        id:0,
        img_url:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.ipeidun.com%2Fstatic%2Fuploads%2Fimage%2Farticle%2F20190926%2F20190926153531_32511.jpg&refer=http%3A%2F%2Fwww.ipeidun.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1655615099&t=c060c96ec41b3d2fa86eaf2950f61b36",
        goto:"",
      },
      {
        id:1,
        img_url:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20181031%2Fe265372760c44322bbec74c3613d47c6.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1655615244&t=b558689b4e5c2faab4f37692d76f1d59",
        goto:"",
      },
      {
        id:2,
        img_url:"https://img2.baidu.com/it/u=2983502653,2800680543&fm=253&fmt=auto&app=138&f=JPEG?w=533&h=288",
        goto:"",
      }
    ],
  },
  onLoad: function (options) {
    this.setSwiperHeight()
  },
 
  //以下为tab事件
  setSwiperHeight: function () {
    let that = this
 
    // 创建节点选择器
    let query = wx.createSelectorQuery();
    query.select('.swiper-view-' + that.data.currentTab).boundingClientRect((rect) => {
      let rectHeight = rect.height; // 获取高度
      that.setData({
        swiperHeight: rectHeight > 200 ? rectHeight : 200
      })
 
      console.log(JSON.stringify(rect))
      console.log(document.body.clientWidth);
    })
    query.exec()
  },
  //tab切换函数，让swiper当前滑块的current的index与tab头部index一一对应
  switchNav: function (e) {
    var index = e.target.dataset.current;
    if (this.data.currentTab == index) {
      return false;
    } else {
      this.setData({
        currentTab: index
      });
    }
 
    this.setSwiperHeight()
  },
  //滑动swiper切换，让swiper当前滑块的current的index与tab头部index一一对应
  tabChange(e) {
    this.setData({
      currentTab: e.detail.current
    })
 
    this.setSwiperHeight()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})